package com.zb.service.imp.middleware.instruction;

import java.util.HashMap;

/**
 * Created by Administrator on 2016/6/7.
 * 1.x协议的所有帧类型枚举
 */
public enum Ev3cInstructions implements Instruction
{
	Heart("51", "心跳", InstructionType.SendByCharger, null),
	HeartReply("52", "服务器回复心跳", InstructionType.ReplyByServer, Ev3cInstructions.Heart),

	StatusChange("53", "遥变", InstructionType.SendByCharger, null),
	StatusChangeReply("59", "服务器回复遥变", InstructionType.ReplyByServer, Ev3cInstructions.StatusChange),

	Bill("54", "账单", InstructionType.SendByCharger, null),
	BillReply("55", "服务器回复账单", InstructionType.ReplyByServer, Ev3cInstructions.Bill),

	ChargerStartCharging("11", "电桩开启充电", InstructionType.SendByCharger, null),
	ChargerStartChargingReply("56", "服务器回复电桩开启充电", InstructionType.ReplyByServer, Ev3cInstructions.ChargerStartCharging),

	ChargerStopCharging("13", "电桩停止充电", InstructionType.SendByCharger, null),
	ChargerStopChargingReply("57", "服务器回复电桩停止充电", InstructionType.ReplyByServer, Ev3cInstructions.ChargerStopCharging),

	ChargerCancelReservation("17", "电桩停止预约", InstructionType.SendByCharger, null),
	ChargerCancelReservationReply("58", "服务器回复电桩停止预约", InstructionType.ReplyByServer, Ev3cInstructions.ChargerCancelReservation),

	CardInfoUpload("75", "桩上传刷卡请求数据", InstructionType.SendByCharger, null),
	CardInfoUploadReply("76", "服务器回复桩上传刷卡", InstructionType.ReplyByServer, Ev3cInstructions.CardInfoUpload),

	Login("A1", "注册", InstructionType.SendByCharger, null),
	LoginReply("A2", "服务器回复注册", InstructionType.ReplyByServer, Ev3cInstructions.Login),

	Logout("A3", "退出登录", InstructionType.SendByCharger, null),
	LogoutReply("A4", "服务器回复退出登录", InstructionType.ReplyByServer, Ev3cInstructions.Logout),


	Charge("10", "开启充电", InstructionType.SendByServer, null),
	ChargeReply("11", "电桩回复开启充电", InstructionType.ReplyByCharger, Ev3cInstructions.Charge),

	StopCharging("12", "停止充电", InstructionType.SendByServer, null),
	StopChargingReply("13", "电桩回复停止充电", InstructionType.ReplyByCharger, Ev3cInstructions.StopCharging),

	Reserve("14", "预约电桩", InstructionType.SendByServer, null),
	ReserveReply("15", "电桩回复预约", InstructionType.ReplyByCharger, Ev3cInstructions.Reserve),

	CancelReservation("16", "取消预约", InstructionType.SendByServer, null),
	CancelReservationReply("17", "电桩回复取消预约", InstructionType.ReplyByCharger, Ev3cInstructions.CancelReservation),

	Restart("18", "重启电桩", InstructionType.SendByServer, null),
	RestartReply("19", "电桩回复重启", InstructionType.ReplyByCharger, Ev3cInstructions.Restart),

	RetrieveIp("30", "查询IP", InstructionType.SendByServer, null),
	RetrieveIpReply("31", "电桩回复查询IP", InstructionType.ReplyByCharger, Ev3cInstructions.RetrieveIp),

	SetIp("32", "设置IP", InstructionType.SendByServer, null),
	SetIpReply("33", "电桩回复设置IP", InstructionType.ReplyByCharger, Ev3cInstructions.SetIp),

	SetTimer("34", "对时", InstructionType.SendByServer, null),
	SetTimerReply("35", "电桩回复对时", InstructionType.ReplyByCharger, Ev3cInstructions.SetTimer),

	RetrieveFee("36", "费率查询", InstructionType.SendByServer, null),
	RetrieveFeeReply("37", "电桩回复费率查询", InstructionType.ReplyByCharger, Ev3cInstructions.RetrieveFee),

	SetFee("38", "费率设置", InstructionType.SendByServer, null),
	SetFeeReply("39", "电桩回复费率设置", InstructionType.ReplyByCharger, Ev3cInstructions.SetFee),

	SetQrcode("77", "设置二维码", InstructionType.SendByServer, null),
	SetQrcodeReply("78", "电桩回复设置二维码", InstructionType.ReplyByCharger, Ev3cInstructions.SetQrcode),

	;


	/*
0x51	心跳报文主动上送	0x52	服务器回复电桩心跳报文
0x53（弃用）	遥变主动上送	0x59（弃用）	服务器回复遥变信息
0x54	账单主动上送	0x55	服务器回复电桩账单确认
0x11	开启充电主动上送	0x56	服务器回复电桩充电开启
0x13	停止充电主动上送	0x57	服务器回复电桩充电停止
0x17	停止预约主动上送	0x58	服务器回复电桩停止预约

0x1B	电池详情主动上送（可选）

0x75	桩上传刷卡请求数据	0x76	服务器返回刷卡请求数据
0xA1	桩上传设备请求注册指令	0xA2	服务器回复注册数据
0xA3	桩上传设备请求退出登录指令	0xA4	服务器回复收到请求



0x10	服务器下发开启指令	0x11	桩开启指令返回
0x12	服务器下发停止指令	0x13	桩停止指令返回
0x14	服务器下发预约指令	0x15	桩预约指令返回
0x16	服务器下发取消预约指令	0x17	桩取消预约指令返回

0x18	服务器下发重启指令	0x19	桩重启指令返回
0x30	服务器下发查询硬件服务器IP	0x31	查询硬件服务器IP返回
0x32	服务器下发设置硬件服务器IP	0x33	桩返回硬件服务器IP
0x34	服务器下发对时指令	0x35	桩返回对时指令
0x36	服务器下发费率查询	0x37	桩回复费率查询指令
0x38	服务器下发费率设置指令	0x39	桩回复费率设置指令
0x52	心跳报文服务器回复	0x51	电桩主动上送心跳报文

0x77	服务器下发设置运营二维码命令	0x78	桩回复设置二维码命令
	* */

	private String code;//帧类型
	private String description;//帧类型描述
	private InstructionType type;//帧类型分类
	private Ev3cInstructions replyFor;//如果是回复类别的帧类型, 表示回复的哪条类型的帧

	private static final HashMap<String, Ev3cInstructions> mapping = new HashMap<>();

	static
	{
		for (Ev3cInstructions e : values())
		{
			mapping.put(e.code, e);
		}
	}

	private Ev3cInstructions(String code, String description, InstructionType type, Ev3cInstructions replyFor)
	{
		this.code = code;
		this.description = description;
		this.type = type;
		this.replyFor = replyFor;
	}

	public static Ev3cInstructions parse(String code)
	{
		return mapping.get(code);
	}

	@Override
	public String code()
	{
		return this.code;
	}

	@Override
	public String description()
	{
		return this.description;
	}

	@Override
	public InstructionType type()
	{
		return this.type;
	}

	public Ev3cInstructions replyFor()
	{
		return this.replyFor;
	}
}
